package com.herui.iot.ui.mime;

import androidx.appcompat.app.AppCompatActivity;
import butterknife.BindView;
import butterknife.OnClick;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.herui.sdyu_lib.utils.StringUtils;
import com.herui.sdyu_lib.utils.ToastUtil;
import com.herui.sport_care.R;
import com.herui.sport_care.app.SportCareApp;
import com.herui.sport_care.ui.BaseSportActivity;
import com.herui.sport_care.ui.main.MainActivity;

public class LoginActivity extends BaseSportActivity {

    @BindView(R.id.userName)
    EditText userName;
    @BindView(R.id.userPassword)
    EditText userPassword;

    private UserPresenter userPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SportCareApp sportCareApp = SportCareApp.getInstance();
        sportCareApp.setEnterMain(false);
        userPresenter = new UserPresenter(userView);
    }

    @Override
    public int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    public void initParam() {

    }

    @OnClick({R.id.btn_login})
    public void onViewClick(View view) {
        switch (view.getId()) {
            case R.id.btn_login:
                String s = userName.getText().toString();
                if (StringUtils.isEmpty(s)){
                    ToastUtil.showMessage("用户名不能为空");
                    return;
                }
                String s1 = userPassword.getText().toString();
                if (StringUtils.isEmpty(s1)){
                    ToastUtil.showMessage("密码不能为空");
                    return;
                }
                userPresenter.login(s, s1);
                break;
            default:
                break;
        }
    }

    UserPresenter.UserView userView = new UserPresenter.UserView() {
        @Override
        public void onLoginSucess() {
            ToastUtil.showMessage("登入成功");
//            Intent i = new Intent(LoginActivity.this, MainActivity.class);
//            i.putExtra("type",1);
            jump(MainActivity.class);
            finish();
        }
    };

}